#!/usr/bin/env python
#! -*- coding: utf-8 -*-
import pymongo

def rename():
    # myclient = pymongo.MongoClient('mongodb://opsmart:q1w2e3r4@10.10.2.149:27017/neikong')
    myclient = pymongo.MongoClient('mongodb://opsmart:q1w2e3r4@10.10.61.31:27017/miaozhen')
    db = myclient['miaozhen']

    db_name_add_list = ['DrugFreqDict', 'DrugUseageDict', 'LisSubItem', 'Module', 'Patient', 'SysRole', 'SysRoleModuleMap',
                        'SysUser', 'SysUserRoleMap', 'Allergic', 'AuditRecord', 'Diagnose', 'DoctorOrder', 'LisDetail', 'LisLab', 'Medicine',
                        'Operation', 'PacsExam', 'Prescription', 'RecipeExcept', 'SurDrug', 'Surveillance', 'VisitCase', 'BlockchainAccountInfo',
                        'BlockchainAccountsStatistics', 'BlockchainStatistics', 'DailyDepartmentExpensiveStatistics', 'DailyHospPrescriptionAuditionStatistics',
                        'DailyMedicineSurveillanceStatistics', 'DailyPharmacistPrescriptionAuditionStatistics', 'DailyPrescriptionAuditionStatistics',
                        'DailyPrescriptionMedicineStatistics', 'DailyProblemPrescriptionStatistics', 'Notification', 'PresOrder', 
                        'PrescriptionRuntimeCountStatistics', 'System']
    db_name_xhhk = ['Hospital', 'SysDict', 'Department', 'Person']

    # Hospital -> XHHK_Application
    # SysDict -> XHHK_Dictionary
    # Department -> XHHK_Team
    # Person -> XHHK_Person

    for db_name in db_name_add_list:
        exec_str = "db.%s.rename('SFLZ_'+'%s')" % (db_name, db_name)
        print 'exec_str: %s',exec_str
        try:
            exec(exec_str)
            print "修改表：", db_name
        except Exception,e:
            print str(e)
            continue

    db.Hospital.rename('XHHK_Application')
    db.SysDict.rename('XHHK_Dictionary')
    db.Department.rename('XHHK_Team')
    db.Person.rename('XHHK_Person')
